# -*- coding: utf-8 -*-

from threading import Thread, active_count, current_thread
import time, os
n = 100
def task():
    global n
    print('%s is running' % os.getpid())
    print('子%s' % current_thread().name)
    n = 0
    time.sleep(3)
if __name__ == '__main__':
    t = Thread(target=task)
    t.start()   # 开启子线程
    t.join()    # 等待子线程运行完
    print(active_count())   # 线程的个数
    print('主%s' % os.getpid()) # 主线程所在的进程pid
    print('主%s' % current_thread().name) # 线程的名字
    print(n)    # 同一个进程的所有线程资源共享
    '''
    运行结果：根据计算机实际运行情况，结果可能不一致
    13412 is running
    子Thread-1
    1
    主13412
    主MainThread
    0
    '''